import React, {Component} from 'react';
import {Form, InputNumber, Space, Button, message} from "antd";
import { apiGetMhcSysConfig ,apiSaveMhcSysConfig} from '@/request/callOrderSetup'
import TheButton from "../../../components/TheButton";
class Index extends Component {
    formRef = React.createRef()
    state = {
        loading: false
    }
    componentDidMount() {
        apiGetMhcSysConfig().then(res=>{
            if (res.code === 0 && res.data){
                let data = res.data
                for (let key in data){
                    data[key] = Number(data[key])
                }
                this.formRef.current.setFieldsValue(data)
            }
        })
    }

    onFinish = (values) => {
        this.setState({
            loading: true
        })
        for (let key in values){
            values[key] = String(values[key])
        }
        apiSaveMhcSysConfig(values).then(res=>{
            if (res.code === 0){
                message.success('保存成功')
            }
            this.setState({
                loading: false
            })
        })
    }

    render() {
        return (
            <div className={"p-layout-box"}>
                <Form
                    labelCol={{span: 3}}
                    wrapperCol={{span: 16}}
                    onFinish={this.onFinish}
                    ref={this.formRef}
                >
                    <Form.Item
                        label="可下单时间"
                    >
                        <span className="ant-form-text">自当天起</span>
                        <Form.Item name="futureAcceptOrderTime" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围在1~999范围内的整数'
                                       }
                                   ]}
                                   initialValue={60}
                        >
                            <InputNumber
                                precision={0}
                                min={1}
                                max={999}
                                placeholder="请输入"
                                style={{width: 50}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">天内可下单</span>
                    </Form.Item>
                    <Form.Item
                        label=" "
                        colon={false}
                    >
                        <span className="ant-form-text">每日下单截止时间为前一日</span>
                        <Form.Item name="banAcceptOrderTime" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围在1~23内的整数'
                                       }
                                   ]}
                                   initialValue={22}
                        >
                            <InputNumber
                                precision={0}
                                min={1}
                                max={23}
                                placeholder="请输入"
                                style={{width: 50}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">时</span>
                    </Form.Item>
                    <Form.Item
                        label="自动退款配置"
                        rules={[{required: true}]}
                    >
                        <span className="ant-form-text">支付后</span>
                        <Form.Item name="autoRefundTime" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围在1~48内的整数'
                                       }
                                   ]}
                                   initialValue={48}
                        >
                            <InputNumber
                                precision={0}
                                min={1}
                                max={48}
                                placeholder="请输入"
                                style={{width: 50}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">小时后未接单，自动退款</span>
                    </Form.Item>
                    <Form.Item
                        label="自动拒绝接单"
                        rules={[{required: true}]}
                    >
                        <span className="ant-form-text">分配订单后</span>
                        <Form.Item name="autoRefuseTime" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围在1~23内的整数'
                                       }
                                   ]}
                                   initialValue={3}
                        >
                            <InputNumber
                                precision={0}
                                min={1}
                                max={23}
                                placeholder="请输入"
                                style={{width: 50}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">小时后，未接单则自动拒绝。</span>
                    </Form.Item>
                    <Form.Item
                        label="变更订单时效性"
                        rules={[{required: true}]}
                    >
                        <span className="ant-form-text">服务开始前</span>
                        <Form.Item name="changeOrderTimeliness" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围在1~23内的整数'
                                       }
                                   ]}
                                   initialValue={4}
                        >
                            <InputNumber
                                precision={0}
                                min={1}
                                max={23}
                                placeholder="请输入"
                                style={{width: 50}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">小时，允许发起变更申请。</span>
                    </Form.Item>
                    <Form.Item
                        label="单次提现最小金额"
                        rules={[{required: true}]}
                    >
                        <Form.Item name="onceWithdrawalMinPrice" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围为0.1~999999.99之间的值'
                                       }
                                   ]}
                                   initialValue={10}
                                   getValueProps={v => ({value: React.$transNum(v, 2, -2), v})}
                                   getValueFromEvent={e => e ? e * 100 : e}
                        >
                            <InputNumber
                                precision={2}
                                min={0.1}
                                max={999999.99}
                                placeholder="请输入"
                                style={{width: 150}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">元</span>
                    </Form.Item>
                    <Form.Item
                        label="单次提现最大金额"
                        rules={[{required: true}]}
                    >
                        <Form.Item name="onceWithdrawalMaxPrice" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围为0.1~999999.99之间的值'
                                       }
                                   ]}
                                   initialValue={99999999}
                                   getValueProps={v => ({value: React.$transNum(v, 2, -2), v})}
                                   getValueFromEvent={e => e ? e * 100 : e}
                        >
                            <InputNumber
                                precision={2}
                                min={0.1}
                                max={999999.99}
                                placeholder="请输入"
                                style={{width: 150}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">元</span>
                    </Form.Item>
                    <Form.Item
                        label="单日最大提现次数"
                        rules={[{required: true}]}
                    >
                        <Form.Item name="oneDayWithdrawalMostNumber" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围为1~10之间的整数'
                                       }
                                   ]}
                                   initialValue={3}
                        >
                            <InputNumber
                                precision={0}
                                min={1}
                                max={10}
                                placeholder="请输入"
                                style={{width: 150}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">次</span>
                    </Form.Item>
                    <Form.Item
                        label="单日最大提现金额"
                        rules={[{required: true}]}
                    >
                        <Form.Item name="oneDayWithdrawalMaxPrice" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围为0.1~999999.99之间的值'
                                       }
                                   ]}
                                   initialValue={99999999}
                                   getValueProps={v => ({value: React.$transNum(v, 2, -2), v})}
                                   getValueFromEvent={e => e ? e * 100 : e}
                        >
                            <InputNumber
                                precision={2}
                                min={0.1}
                                max={999999.99}
                                placeholder="请输入"
                                style={{width: 150}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">元</span>
                    </Form.Item>
                    <Form.Item
                        label="单笔提现审核金额"
                        rules={[{required: true}]}
                    >
                        <span className="ant-form-text">超过</span>
                        <Form.Item name="onceWithdrawalExaminePrice" noStyle
                                   rules={[
                                       {
                                           required: true,
                                           message: '请输入值范围为0.01~999999.99之间的值'
                                       }
                                   ]}
                                   initialValue={99999999}
                                   getValueProps={v => ({value: React.$transNum(v, 2, -2), v})}
                                   getValueFromEvent={e => e ? e * 100 : e}
                        >
                            <InputNumber
                                precision={2}
                                min={0.01}
                                max={999999.99}
                                placeholder="请输入"
                                style={{width: 150}}
                            />
                        </Form.Item>
                        <span className="ant-form-text">元需人工审核</span>
                    </Form.Item>
                    <Form.Item wrapperCol={{span: 12, offset: 3}}>
                        <TheButton haspermi={['call:orderSetup:save']}  loading={this.state.loading} type="primary" size={'middle'} htmlType="submit">
                            保存
                        </TheButton>
                    </Form.Item>
                </Form>
            </div>
        );
    }
}

export default Index;
